﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Com.CMS263.PO;
using Com.CMS263.Util;
using Com.CMS263.DAO;

namespace Com.CMS263.BLL
{
    public class ArticleBLL
    {
        ArticleDAO artDAO = new ArticleDAO();
        public bool Add(Article art)
        {
            if (string.IsNullOrEmpty(art.title))
            {
                StringUtil.Alert("请填写文章标题", "-1");
            }
            else if (string.IsNullOrEmpty(art.content))
            {
                StringUtil.Alert("请填写文章内容", "-1");
            }
            else if (art.addDate == null)
            {
                StringUtil.Alert("请填写添加时间","-1");
            }
            return artDAO.Add(art);
        }
        public Article GetArticleById(int id)
        {
           return  artDAO.GetArticleById(id);
        }
        public bool ModifyArt(Article art)
        {
            return  artDAO.Modify(art);
        }

       
        /// <summary>
        /// 得到文章分页列表
        /// </summary>
        /// <param name="pid">文章分编号</param>
        /// <param name="page">当前页数</param>
        /// <param name="pageSize">每页条数</param>
        /// <returns></returns>
        public IList<Article> GetArticleById(int pid, int page, int pageSize)
        {
            return artDAO.GetArticleByPid(pid,page,pageSize);
        }

        public Article GetArticleByPid(int pid)
        {
             return artDAO.GetArticleByPid(pid);
        }

        public int GetTotalByPid(int pid)
        {
            return artDAO.GetTotalByPid(pid);
        }
       /// <summary>
       /// 文章分页列表
       /// </summary>
       /// <param name="pid">父类编号</param>
       /// <param name="page">当前页数</param>
       /// <param name="pageSize">每页条数</param>
       /// <param name="key">查询 条件</param>
       /// <returns></returns>
        public IList<Article> GetArticleById(int pid, int page, int pageSize, string key)
        {
            return artDAO. GetArticleById( pid,  page,  pageSize,  key);
        }

        public int GetTotalByPid(int pid, string key)
        {
            return artDAO.GetTotalByPid(pid,key);
        }
        /// <summary>
        /// 根据雷编号找出制定条数的文章
        /// </summary>
        /// <param name="pid">类别编号</param>
        /// <param name="top">找出几条</param>
        /// <returns></returns>
        public IList<Article> GetTopArticleByPid(int pid, int top)
        {
            return artDAO.GetTopArticleByPid(pid, top);
        }

        public IList<Article> GetArticleByPid(int pid, int page, int pageSize)
        {
          return  artDAO. GetArticleByPid( pid, page, pageSize);
        }

        public void DeleteArtById(int id)
        {
            artDAO.DeleteArtById(id);
        }
    }
}
